package LYL.Service

import bean.MajorCategoryMatch
import org.apache.spark.streaming.dstream.DStream
import org.apache.spark.sql.functions._
import util.SparkUtil

object MajorCategoryAnalysisService {
  def analyzeMajorCategoryImpact(resumeDataStream: DStream[MajorCategoryMatch]): Unit = {
    val spark = SparkUtil.takeSpark()
    import spark.implicits._

    resumeDataStream.foreachRDD { rdd =>
      if (!rdd.isEmpty()) {
        val df = rdd.toDF()

        // 按专业类别和筛选结果分组统计
        val resultDF = df.groupBy("major_type", "screening_result")
          .agg(count("*").as("数量"))
          .orderBy("major_type", "screening_result")

        // 输出分析结果
        println("专业类别对筛选结果影响分析：")
        resultDF.show()

        // 保存结果到数据库（可使用现有DAO层）
        // EducationLevelAnalysisDAO.saveAnalysisResult(resultDF, "major_category_result")
      }
    }
  }
}